/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package TimeRecording.TimeClockServer.messages.tx;

import TimeRecording.TimeClockServer.dtos.DatabaseTransaction;
import TimeRecording.TimeClockServer.messages.ClockMessage;
import java.util.Formatter;

/**
 *
 * @author david
 */
public class NegativeResponseMessage extends ClockMessage {

    private final static String MSG_FORMAT =
            "[HDR]NR00[RS]" +
                "%1$5s[RS]" +        // Prompt number (5 chars)
                "%2$s[RS]" +         // Free format message
                "5000[RS]" +         // Message timeout (4 digits)
                "1[RS]" +            // Bad Beep (boolean - 0 | 1)
                "0[RS]";

    private final static String USER_MSG_FORMAT = "%1$-20s%2$-20s";

    public NegativeResponseMessage(DatabaseTransaction transaction) {
        
        super(new Formatter().format(MSG_FORMAT,
                transaction.getPrompt(),
                getMessage(transaction)).toString());
    }

    private static String getMessage(DatabaseTransaction transaction) {

        String line1;
        String line2;
        
        if (transaction.getBadgeDetails() == null) {
            line1 = "Badge " + transaction.getBadgeNo();
            line2 = "Not Recognised";            
        } else {
            line1 = "Badge " + transaction.getBadgeNo();
            line2 = "Not Associated";
        }
        
        return new Formatter().format(USER_MSG_FORMAT, line1, line2).toString();
    }
}
